home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5501 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: mudskipper.cac.psu.edu!user
  2. From: fcusack@tdx.org (frank.)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: simple code, argc, argv, strcmp()
  5. Date: Wed, 07 Feb 1996 20:17:16 -0400
  6. Organization: Penn State University, Center for Academic Computing
  7. Message-ID: <fcusack-0702962017160001@mudskipper.cac.psu.edu>
  8. References: <11f7cc$17261a.3b3@daprez> <4etj7c$bma@news.iag.net> <fcusack-0202961621470001@mudskipper.cac.psu.edu> <31177C77.167EB0E7@texas.net> <fcusack-0702961519200001@mudskipper.cac.psu.edu>
  9. NNTP-Posting-Host: mudskipper.cac.psu.edu
  10.  
  11. In article <fcusack-0702961519200001@mudskipper.cac.psu.edu>,
  12. fcusack@tdx.org (frank.) wrote:
  13.  
  14. > In article <31177C77.167EB0E7@texas.net>, Michael Douglass
  15. > <mikedoug@texas.net> wrote:
  16. > > > > >int main (int argc, char **argv) {
  17. > > > > >
  18. > > > > >  void Usage   (void);
  19. > > > > >  void Encode (int, char **);
  20. > > > > >  void Decode (int, char **);
  21. > > > > >
  22. > > > > >  if (!strcmp(argv[1],"-d") || !strcmp(argv[1],"-e")) {
  23. > > > > >    Usage();
  24. > > > > >  }
  25. > > > > <snip>
  26. > > 
  27. > > > argv[1] is always guaranteed to exist. It is simply NULL if there were no
  28. > > > arguments.
  29. > > 
  30. > > Even if this is so... You still do *not* want to call strcmp with a NULL
  31. > pointer
  32. > > now do we?  Does that not make your argument moot, and make the
  33. previous point
  34. > > that you should always check argc to make sure that you *have* at least
  35. > one argument
  36. > > a very good argument?
  37. > well, a) argv[1] is not guaranteed to exist. Sorry for that mistake.
  38. > b) I meant that if argv[0] is passed (and is the command name), then
  39. >    argv[1] is a pointer to a null string, not a null pointer.
  40.  
  41. ARG! (pun intended :) )
  42.  
  43. of course, the above is wrong. argv[argc] is guaranteed to be NULL.
  44. ~Frank
  45.  -- I am Pentium of Borg.  Division is futile.  You will be approximated. --
  46.  --   If you build it, they will come --> http://www.tdx.org/~fcusack/    --
  47.  -- PGP key fingerprint: 01 C0 C0 B9 CC 78 67 0F  3F 64 80 65 8B 0F F9 EA --
  48.